# Copyright (C) 2007 Samuel Abels, http://debain.org
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
from Token import Token
from Term  import Term
import Variable

class Define(Token):
    def __init__(self, parser, parent):
        Token.__init__(self, 'Define', parser)
        self.parent = parent

        parser.expect(self, 'keyword', 'define')
        parser.expect(self, 'whitespace')

        # Extract the variable name.
        (type, self.varname) = parser.token()
        parser.expect(self, 'varname')
        parser.expect(self, 'whitespace')

        # Now expect a term.
        self.term = Term(parser, parent)
        parser.next_if(self, 'whitespace')

        parser.expect(self, 'semicolon')
        self.parent.define(**{self.varname: None})


    def dump(self, indent = 0):
        print (' ' * indent) + self.name, self.varname, 'start'
        self.term.dump(indent + 1)
        print (' ' * indent) + self.name, self.varname, 'start'
